package basisApi

import (
	"github.com/Sir-yuChen/funAnalyse/model"
	"github.com/Sir-yuChen/funAnalyse/model/common/response"
	"github.com/Sir-yuChen/funAnalyse/model/request"
	"github.com/Sir-yuChen/funAnalyse/utils"
	"github.com/gin-gonic/gin"
)

type CommonController struct{}

// GetStockApiResource 多条件查询
// @Summary 系统接口资源获取
// @Tags 公共接口
// @Accept application/json
// @Produce application/json
// @Param data body model.StockApiResource true "请求参数"
// @response 200 {object} response.Response  "接口返回信息"
// @Router /funAnalyse/common/getStockApiResource [GET]
func (co *CommonController) GetStockApiResource(c *gin.Context) {
	var req model.StockApiResource
	err := c.ShouldBindJSON(&req)
	if err != nil {
		utils.ErrValidatorResp(err, "GetStockApiResource", req, c)
		return
	}
	apiReturn := commonService.GetStockApiResource(&req)
	response.WithApiReturn(apiReturn, c)
	return
}

// GetVerificationCode 获取验证码
// @Summary 获取验证码
// @Tags 公共接口
// @Security ApiKeyAuth
// @Param data body request.VerificationCodeRequest true "请求参数"
// @response 200 {object} response.Response "返回信息"
// @Router /funAnalyse/common/verification [Get]
func (co *CommonController) GetVerificationCode(c *gin.Context) {
	var re request.VerificationCodeRequest
	//ShouldBindJSON 单次绑定 多次调用 error  ShouldBindBodyWith不会异常
	err := c.ShouldBindJSON(&re)
	if err != nil {
		utils.ErrValidatorResp(err, "GetVerificationCode", re, c)
		return
	}
	//获取用户IP
	ipAddr := utils.GetIpAddr(c.Request)
	re.IpAddr = ipAddr
	apiReturn := commonService.GetVerificationCode(&re)
	response.WithApiReturn(apiReturn, c)
}

// CheckVerificationCode  校验验证码
// @Summary 校验验证码
// @Tags 公共接口
// @Accept application/json
// @Produce application/json
// @Param data body request.VerificationCodeRequest true "请求参数"
// @response 200 {object} response.Response "返回信息"
// @Router /funAnalyse/common/checkVerificationCode [Get]
func (co *CommonController) CheckVerificationCode(c *gin.Context) {
	var re request.VerificationCodeRequest
	//ShouldBindJSON 单次绑定 多次调用 error  ShouldBindBodyWith不会异常
	err := c.ShouldBindJSON(&re)
	if err != nil {
		utils.ErrValidatorResp(err, "AutoCode", re, c)
		return
	}
	//获取用户IP
	ipAddr := utils.GetIpAddr(c.Request)
	re.IpAddr = ipAddr
	apiReturn := commonService.CheckVerificationCode(&re)
	response.WithApiReturn(apiReturn, c)
}

// AutoCode 代码生成器
// @Summary 自动生成表crud
// @Tags 公共接口
// @Accept application/json
// @Produce application/json
// @Param data body request.AutoCodeRequest true "请求参数"
// @response 200 {object} response.Response "返回用户信息"
// @Router /funAnalyse/common/autoCode [Get]
func (co *CommonController) AutoCode(c *gin.Context) {
	var req request.AutoCodeRequest
	err := c.ShouldBindJSON(&req)
	if err != nil {
		utils.ErrValidatorResp(err, "AutoCode", req, c)
		return
	}
	apiReturn := commonService.AutoCode(&req)
	response.WithApiReturn(apiReturn, c)
	return
}

// GetStockTableStructure 获取表结构信息
// @Summary 获取表结构信息
// @Tags 公共接口
// @Accept application/json
// @Produce application/json
// @Param data body request.TableStructure true "请求参数"
// @response 200 {object} response.Response "返回用户信息"
// @Router /funAnalyse/common/getStockTableStructure [Get]
func (co *CommonController) GetStockTableStructure(c *gin.Context) {
	var req request.TableStructure
	err := c.ShouldBindJSON(&req)
	if err != nil {
		utils.ErrValidatorResp(err, "GetStockTableStructure", req, c)
		return
	}
	apiReturn := commonService.GetStockTableStructure(&req)
	response.WithApiReturn(apiReturn, c)
	return
}

/*
path 该类型参数直接拼接在URL中，如Demo中HandleGetFile：

	// @Param id path integer true "文件ID"
	query 该类型参数一般是组合在URL中的，如Demo中HandleHello

	// @Param who query string true "人名"
	formData 该类型参数一般是POST,PUT方法所用，如Demo中HandleLogin

	// @Param user formData string true "用户名" default(admin)
	body 当Accept是JSON格式时，我们使用该字段指定接收的JSON类型

	// @Param param body main.JSONParams true "需要上传的JSON"
*/
